package com.kecheng.action;

import java.util.List;

import com.kecheng.dao.TixianDao;
import com.kecheng.dao.YongjinDao;
import com.kecheng.pojo.Tixian;
import com.kecheng.pojo.Yongjin;
import com.kecheng.util.Sendmoney;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

@Action(value = "tixian", results = {
		@Result(name = "fxtixians", location = "/admin/seller/fxtixian.jsp"),
		@Result(name = "tixians", location = "/w/tixian.jsp"),
		@Result(name = "tixian2", location = "/admin/seller/tixian.jsp"),
		@Result(name = "tixian1", location = "/w/tixian1.jsp"),
		@Result(name = "yongjins", location = "/w/yongjin.jsp"),
		@Result(name = "fail", location = "/fail.jsp"),
})
@AllowedMethods(value = {("regex:.*")})
public class TixianAction extends BaseAction {

	private Tixian tixian;
	@Autowired
	private TixianDao tixianDao;
	private List<Tixian> tixians;
	private Yongjin yongjin;
	@Autowired
	private YongjinDao yongjinDao;
	private List<Yongjin> yongjins;
	private Double money;

	/**
	 * 提现接口
	 * @return
	 */
	public String apply() {
		//转账
		Sendmoney s = new Sendmoney();
		String ip = org.apache.struts2.ServletActionContext.getRequest().getRemoteAddr();
		String jieguo = s.send(tixian.getOpenid(), ip, tixian.getMoney());
		if(jieguo!=null){
			tixian.setStatus("成功");
			dao.update(tixian);
			//更新team
		}else{
			System.out.println("提现失败了~");
		}
		return"";
	}
	
	
	/**
	 * 提现通过
	 * 
	 * @return
	 */
//
//	public String pass() {
//		tixian = tixianDao.findbyid(tixian.getId());
//		team = teamDao.findbyid(tixian.getSid());
//		// TODO:
//
//		Sendmoney s = new Sendmoney();
//
//		String ip = org.apache.struts2.ServletActionContext.getRequest()
//				.getRemoteAddr();
//		String jieguo = s.send(team.getSellerid(), ip, tixian.getMoney());
//
//		if (jieguo != null) {
//			tixian.setStatus("审核成功");
//			tixianDao.update(tixian);
//		} else {
//			msg = "fail";
//		}
//
//		if (page == null) {
//			page = 1;
//		}
//		tixians = tixianDao.findall1(page);
//		allpage = tixianDao.findallpage();
//		return "tixian2";
//	}

	/**
	 * 拒绝提现
	 * 
	 * @return
	 */
//	public String refuse() {
//		tixian = tixianDao.findbyid(tixian.getId());
//		team = teamDao.findbyid(tixian.getSid());
//		team.setMoney(team.getMoney() + tixian.getMoney());
//		teamDao.update(team);
//		tixian.setStatus("审核失败");
//		tixianDao.update(tixian);
//		return findall2();
//	}

	public String findall() {
		tixians = tixianDao.findall(team.getId());
		team = teamDao.findbyid(team.getId());
		if (tixians.size() > 0) {
			msg = "yes";
		}
		return "tixians";
	}

	public String findbysid() {

		tixians = tixianDao.findall(team.getId());

		return "fxtixians";
	}

	public String findall2() {
		if (page == null) {
			page = 1;
		}
		tixians = tixianDao.findall1(page);
		allpage = tixianDao.findallpage();
		return "tixian2";
	}

	public String findall1() {
		try {
			yongjins = yongjinDao.findall(team.getId());
			team = teamDao.findbyid(team.getId());
			if (yongjins.size() > 0) {
				msg = "yes";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "yongjins";
	}

	public Tixian getTixian() {
		return tixian;
	}

	public void setTixian(Tixian tixian) {
		this.tixian = tixian;
	}

	public Yongjin getYongjin() {
		return yongjin;
	}

	public void setYongjin(Yongjin yongjin) {
		this.yongjin = yongjin;
	}

	public List<Tixian> getTixians() {
		return tixians;
	}

	public void setTixians(List<Tixian> tixians) {
		this.tixians = tixians;
	}


	public List<Yongjin> getYongjins() {
		return yongjins;
	}

	public void setYongjins(List<Yongjin> yongjins) {
		this.yongjins = yongjins;
	}

	public Double getMoney() {
		return money;
	}

	public void setMoney(Double money) {
		this.money = money;
	}


}
